package org.helgoboss.single_source_builder_main

class ProjectDescriptor (
    val parentArtifact: Option[Artifact],
    val artifact: Artifact,
    val dependencies: Set[Artifact],
    val primaryClassName: String
) {
    
    def parentArtifactXml = {
        if (parentArtifact.isDefined) {
            val parentArtifactValue = parentArtifact.get
            import parentArtifactValue._
            <parent>
                {groupIdXml}
                {artifactIdXml}
                {versionXml}
            </parent>
        } else {
            null
        }
    }
    
    def artifactXml = {
        List (
            artifact.groupIdXml,
            artifact.artifactIdXml,
            artifact.versionXml,
            artifact.packagingXml,
            artifact.nameXml
        ).filter(_ != null)
    }
    
    def dependenciesXml = {
        <dependencies>
            {
                for (dep <- dependencies) yield {
                    <dependency>
                        {dep.groupIdXml}
                        {dep.artifactIdXml}
                        {dep.versionXml}
                        {dep.typeXml}
                    </dependency>
                }
            }
        </dependencies>
    }
}